package com.motong.gongdan.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.motong.gongdan.entity.CustomEvent;
import com.motong.gongdan.service.CustomEventService;
import com.motong.gongdan.util.CronUtil;
import com.motong.gongdan.util.QuartzUtil;
import org.quartz.Scheduler;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.List;

/**
 * @author:fff
 * @time:2022/6/24
 */
@Component
public class GroupTask {

    @Resource
    private Scheduler scheduler;
    @Resource
    CustomEventService customEventService;

    @PostConstruct
    public void dynamicGroupTask(){
        List<CustomEvent> list = customEventService.list(new QueryWrapper<CustomEvent>()
                .eq("type",0).eq("custom_type",1).eq("state",0));
        if(!CollectionUtils.isEmpty(list)){
            list.forEach(l->{
                QuartzBean qb = customEventService.handleEventTime(l);
                QuartzUtil.createScheduleJob(scheduler,qb);
            });
        }
    }

}
